<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once("conn.php");
$result = 0;
$db = new DBC();
if (isset($_GET['ids']) && isset($_GET['direct'])) {
    $ids = $_GET['ids'];
    $ids = trim($ids);
    $array = explode(",", $ids);
    $dir = "../game/question/";
    $file_code = "";
    foreach ($array as $code) {
        if ($code != '') {
            $sql = "SELECT difficult FROM t_game_question WHERE code = '" . $code . "'";
            $temp = $db->fetchData($sql);
            if ($temp != false && count($temp) > 0) {
                $difficult = $temp[0]['difficult'];
                $file = $dir . $code . $difficult . ".unity3d";
                if (file_exists($file)) {
                    $direct = $_GET['direct'];
                    if ($direct == "up") {
                        
                        $url = getDomain()."game/question/" . $code . $difficult . ".unity3d";
                        $sql = "UPDATE t_game_question SET status = 1,url = '" . $url . "' WHERE code = '" . $code . "'";
                    } else if ($direct == "down") {
                        $sql = "UPDATE t_game_question SET status = -1 WHERE code = '" . $code . "'";
                    }
                    if ($db->execute($sql)) {
                        //success
                        //        echo "<script language='javascript'>alert('\u6210\u529f'); </ script>";
                        $result = 0;
                    } else {
                        //failue
                        $result = -2; // db fail
                    }
                } else {
                    $result = -1; // file does not exist
                    $file_code = $code;
                }
            }
        }
    }
    if (isset($_GET['page'])) {
        $page = $_GET['page'];
    } else {
        $page = 0;
    }
}
if ($result == -2) {
    $msg = "发布失败";
    echo "<script language='javascript'>alert('" . $msg . "'); </script>";
} else if ($result == -1) {
    $msg = "文件 " . $file_code . ".unity3d 不存在";
    echo "<script language='javascript'>alert('" . $msg . "'); </script>";
}
echo "<script language='javascript'>location='questionList.php?menu=question&page=" . $page . "';</script>";
?>